package com.ming.easyDevelop.controller;

import com.ming.easyDevelop.controller.base.BaseController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import com.ming.easyDevelop.service.OrdersService;
import com.ming.easyDevelop.controller.base.ValidListBean;
import javax.validation.Valid;
import com.ming.easyDevelop.entity.po.Orders;
import com.ming.easyDevelop.entity.vo.ResponseVo;
import com.ming.easyDevelop.entity.query.OrdersQuery;
import java.util.List;
/**
 * @Description  Controller API
 * @Author ming
 * @Date 2024/07/10
 */
@RequestMapping("/api/orders")
@RestController
public class OrdersController extends BaseController {
	@Resource
	private OrdersService ordersService;

	@RequestMapping("/list")
	public ResponseVo getDataList(OrdersQuery query){
		return getSuccessResponseVo(this.ordersService.findListByParam(query));
	}
	@PostMapping("/add")
	public ResponseVo add(@Valid @RequestBody Orders bean){
		this.ordersService.add(bean);
		return getSuccessResponseVo(null);
	}

	@PostMapping("/addOrUpdate")
	public ResponseVo addOrUpdate(@Valid @RequestBody Orders bean){
		this.ordersService.addOrUpdate(bean);
		return getSuccessResponseVo(null);
	}

	@PostMapping("/addBatch")
	public ResponseVo addBatch(@RequestBody ValidListBean<Orders> list){
		this.ordersService.addBatch(list.getData());
		return getSuccessResponseVo(null);
	}

	@PostMapping("/addOrUpdateBatch")
	public ResponseVo addOrUpdateBatch(@RequestBody ValidListBean<Orders> list){
		this.ordersService.addOrUpdateBatch(list.getData());
		return getSuccessResponseVo(null);
	}

	/**
	 * 根据OrderID查询
	 */
	@GetMapping("/orderID")
	public ResponseVo getByOrderID(Integer orderID){
		return getSuccessResponseVo(this.ordersService.getByOrderID(orderID));
	}

	/**
	 * 根据OrderID更新
	 */
	@PutMapping("/orderID")
	public ResponseVo updateByOrderID(@Valid Orders bean, Integer orderID){
		this.ordersService.updateByOrderID(bean,orderID);
		return getSuccessResponseVo(null);
	}

	/**
	 * 根据OrderID删除
	 */
	@DeleteMapping("/orderID")
	public ResponseVo deleteByOrderID(Integer orderID){
		this.ordersService.deleteByOrderID(orderID);
		return getSuccessResponseVo(null);
	}

}